/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GraphPackage;

import GUIUtilities.LabelManager;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Heather
 */
public class Graph extends JPanel
{

  protected double maxValue = 100;
  protected double minValue = -100;
  // this could be either x or y... in the case of vertical bar graphs and
  // line graphs, it's y, but it's x for horizontal bar graphs
  protected double maxDimension;
  protected double minDimension;
  protected double topLabelBorder = 70;
  protected double bottomLabelBorder = 75;
  protected double leftLabelBorder = 75;
  protected double rightBorder = 10;
  protected JLabel graphTitleLabel = new JLabel();
  protected String name = "";
  protected Random randGen = new Random();
  protected double graphWidth;
  protected double graphHeight;
  protected Color bgColor = new Color(245, 245, 245);
  protected Vector<JLabel> xAxisLabels = new Vector<JLabel>();
  protected Vector<JLabel> yAxisLabels = new Vector<JLabel>();
  protected JLabel detailsLabel = new JLabel("<html>" + "hey" + "<p>" + "this is a popup" + "<p>" + "</html>");
  // this is how off the arrow the label will set
  protected int detailsLabelXOffset = -20;
  protected double xAxisLabelsIncrement = 10;
  protected double yAxisLabelsIncrement = 10;

  public Graph()
  {
    super();
    detailsLabel.setBackground(Color.pink);
    calculateVariables();
  }

  protected void calculateVariables()
  {
    graphWidth = getSize().width - leftLabelBorder - rightBorder;
    graphHeight = getSize().height - topLabelBorder - bottomLabelBorder;
  }

  protected void setupDetailsLabel()
  {
    remove(detailsLabel);
    Component[] theComponents = getComponents();
    // remove all the other components
    for (Component c : theComponents)
    {
      remove(c);
    }

    add(detailsLabel);
    for (Component c : theComponents)
    {
      add(c);
    }
  }

  public void setGraphTooltipText(List<String> newText)
  {
    String biggestString = "";
    String newString = "<html>";
    for (String s : newText)
    {
      newString += s + "<p>";
      if (s.length() > biggestString.length())
        biggestString = s;
    }
    newString += "</html>";

    JLabel partialLabel = new JLabel(biggestString);
    Dimension partialSize = LabelManager.getLabelDimensions(partialLabel);
    int newHeight = partialSize.height * newText.size();
    Dimension newSize = new Dimension(partialSize.width, newHeight);

    detailsLabel.setText(newString);
    detailsLabel.setSize(newSize);
    detailsLabel.setPreferredSize(newSize);
    repaint();
  }

  /**
   * @return the xAxisLabelsIncrement
   */
  public double getXAxisLabelsIncrement()
  {
    return xAxisLabelsIncrement;
  }

  /**
   * @param xAxisLabelsIncrement the xAxisLabelsIncrement to set
   */
  public void setXAxisLabelsIncrement(int xAxisLabelsIncrement)
  {
    this.xAxisLabelsIncrement = xAxisLabelsIncrement;
  }

  /**
   * @return the yAxisLabelsIncrement
   */
  public double getYAxisLabelsIncrement()
  {
    return yAxisLabelsIncrement;
  }

  /**
   * @param yAxisLabelsIncrement the yAxisLabelsIncrement to set
   */
  public void setYAxisLabelsIncrement(int yAxisLabelsIncrement)
  {
    this.yAxisLabelsIncrement = yAxisLabelsIncrement;
  }
}
